package com.creaminomedia.epictures;

import java.io.File;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Environment;
import android.widget.Toast;

public class SendPictures {
	public static void WhatsApp() {
		Intent waIntent = new Intent(Intent.ACTION_SEND);
	    waIntent.setType("image/jpeg");
	    SingleView.SaveImage(1);
		Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory()
			      + File.separator + "Epictures" + File.separator + SingleView.pictures[SingleView.piccount]));
		waIntent.putExtra(Intent.EXTRA_STREAM, uri);
	    waIntent.setPackage("com.whatsapp");
	    Intent waChooser = Intent.createChooser(waIntent, "Share with");
        waChooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	    if (SendPictures.checkWA()) {
	    	SingleView.context.startActivity(waChooser);
	    } else {
	    	Toast.makeText(SingleView.context, "WhatsApp was not found",
	    		      Toast.LENGTH_SHORT).show();
	    }
	}
	
	public static void SMS() {
		Intent sendIntent = new Intent(Intent.ACTION_VIEW);         
		sendIntent.setData(Uri.parse("sms:"));
		sendIntent.putExtra("sms_body", "Hey, I found this picture via Epictures: " + SingleView.baseUrlPics + SingleView.pictures[SingleView.piccount]);
		sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		SingleView.context.startActivity(sendIntent);
	}
	
	public static void FB() {
		    Uri uri = Uri.parse("http://m.facebook.com/sharer.php?u=" +
		            SingleView.baseUrlPics + SingleView.pictures[SingleView.piccount]);
		    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		    SingleView.context.startActivity(intent);
	}
	
	public static boolean checkWA() {
		try{
		    SingleView.context.getPackageManager().
		            getApplicationInfo("com.whatsapp", 0 );
		    return true;
		} catch( PackageManager.NameNotFoundException e ){
		    return false;
		}
	}
}
